import { ApiProperty } from '@nestjs/swagger';
import { User } from './user.entity';
import {
	Column,
	CreateDateColumn,
	Entity,
	Index,
	ManyToOne,
	PrimaryGeneratedColumn,
	UpdateDateColumn,
} from 'typeorm';

@Entity()
@Index(['userTelegramId', 'traderTelegramId'], { unique: true })
export class Subscribe {
	constructor(props?: Partial<Subscribe>) {
		Object.assign(this, props);
	}

	@PrimaryGeneratedColumn()
	public id!: string;

	// Инициатор запроса
	@ManyToOne(() => User, (user) => user.telegramId)
	public user!: User;
	@Column()
	userTelegramId!: string;

	// Инициатор запроса
	@ManyToOne(() => User, (user) => user.telegramId)
	public trader!: User;
	@Column()
	traderTelegramId!: string;

	@ApiProperty({ example: true, description: 'status' })
	@Column({
		type: 'boolean',
		default: false,
	})
	public status!: boolean;

	@ApiProperty({ example: '20', description: 'summa subscribe' })
	@Column({
		type: 'numeric',
		default: 0,
	})
	public sum!: number;

	@ApiProperty({ example: 'smirnova', description: 'login' })
	@CreateDateColumn({ nullable: true, name: 'created_at' })
	createdAt!: Date;

	@ApiProperty({ example: 'smirnova', description: 'login' })
	@UpdateDateColumn({ nullable: true, name: 'updated_at' })
	updatedAt!: Date;
}
